<!-- 储存组织相关控件 -->
<template>
  <!-- 人员姓名 -->
  <HumanName
    v-if="code === 'HUMAN_NAME'"
    :props="getProps"
    :name="name"
    :required="required"
    v-model:one-value="oneValue"
    :regex="regex"
    :disabled="disabled"
  >
  </HumanName>

  <!-- 性别 -->
  <HumanSex
    v-if="code === 'HUMAN_SEX'"
    :props="getProps"
    :name="name"
    :required="required"
    v-model:one-value="oneValue"
    :regex="regex"
    :disabled="disabled"
  >
  </HumanSex>

  <!-- 曾用名 -->
  <HumanPreName
    v-if="code === 'HUMAN_PRE_NAME'"
    :props="getProps"
    :name="name"
    :required="required"
    v-model:one-value="oneValue"
    :regex="regex"
    :disabled="disabled"
  >
  </HumanPreName>

  <!-- 英文名 -->
  <HumanEnglishName
    v-if="code === 'HUMAN_ENGLISH_NAME'"
    :props="getProps"
    :name="name"
    :required="required"
    v-model:one-value="oneValue"
    :regex="regex"
    :disabled="disabled"
  >
  </HumanEnglishName>

  <!-- 出生日期 -->
  <HumanBirthday
    v-if="code === 'HUMAN_BIRTHDAY'"
    :props="getProps"
    :name="name"
    :required="required"
    v-model:one-value="oneValue"
    :regex="regex"
    :disabled="disabled"
  >
  </HumanBirthday>

  <!-- 证件类型 -->
  <HumanCertificateType
    v-if="code === 'HUMAN_CERTIFICATE_TYPE'"
    :props="getProps"
    :name="name"
    :required="required"
    v-model:one-value="oneValue"
    :regex="regex"
    :disabled="disabled"
  >
  </HumanCertificateType>

  <!-- 证件号码 -->
  <HumanId
    v-if="code === 'HUMAN_ID'"
    :props="getProps"
    :name="name"
    :required="required"
    v-model:one-value="oneValue"
    :regex="regex"
    :disabled="disabled"
  >
  </HumanId>

  <!-- 手机号码 -->
  <HumanPhone
    v-if="code === 'HUMAN_PHONE'"
    :props="getProps"
    :name="name"
    :required="required"
    v-model:one-value="oneValue"
    :regex="regex"
    :disabled="disabled"
  >
  </HumanPhone>

  <!-- 工号 -->
  <HumanCode
    v-if="code === 'HUMAN_CODE'"
    :props="getProps"
    :name="name"
    :required="required"
    v-model:one-value="oneValue"
    :regex="regex"
    :disabled="disabled"
  >
  </HumanCode>

  <!-- 电子邮箱 -->
  <HumanEmail
    v-if="code === 'HUMAN_EMAIL'"
    :props="getProps"
    :name="name"
    :required="required"
    v-model:one-value="oneValue"
    :regex="regex"
    :disabled="disabled"
  >
  </HumanEmail>

  <!-- 民族 -->
  <HumanNation
    v-if="code === 'HUMAN_NATION'"
    :props="getProps"
    :name="name"
    :required="required"
    v-model:one-value="oneValue"
    :regex="regex"
    :disabled="disabled"
  >
  </HumanNation>

  <!-- 籍贯 -->
  <HumanOrigin
    v-if="code === 'HUMAN_ORIGIN'"
    :props="getProps"
    :name="name"
    :required="required"
    v-model:one-value="oneValue"
    :regex="regex"
    :disabled="disabled"
  >
  </HumanOrigin>

  <!-- 户籍所在地 -->
  <HumanResidence
    v-if="code === 'HUMAN_RESIDENCE'"
    :props="getProps"
    :name="name"
    :required="required"
    v-model:one-value="oneValue"
    :regex="regex"
    :disabled="disabled"
  >
  </HumanResidence>

  <!-- 现居住地（详细） -->
  <HumanAddress
    v-if="code === 'HUMAN_ADDRESS'"
    :props="getProps"
    :name="name"
    :required="required"
    v-model:one-value="oneValue"
    :regex="regex"
    :disabled="disabled"
  >
  </HumanAddress>

  <!-- 工作性质 -->
  <HumanJobNature
    v-if="code === 'HUMAN_JOB_NATURE'"
    :props="getProps"
    :name="name"
    :required="required"
    v-model:one-value="oneValue"
    :regex="regex"
    :disabled="disabled"
  >
  </HumanJobNature>

  <!-- 员工状态 -->
  <HumanState
    v-if="code === 'HUMAN_STATE'"
    :props="getProps"
    :name="name"
    :required="required"
    v-model:one-value="oneValue"
    :regex="regex"
    :disabled="disabled"
  >
  </HumanState>

  <!-- 试用期 -->
  <HumanProbation
    v-if="code === 'HUMAN_PROBATION'"
    :props="getProps"
    :name="name"
    :required="required"
    v-model:one-value="oneValue"
    :regex="regex"
    :disabled="disabled"
  >
  </HumanProbation>
</template>

<script setup lang="ts">
const props = withDefaults(
  //参数说明
  defineProps<{
    componentType: string;
    code: string;
    props: { [propName: string]: any };
    name?: string;
    required: boolean;
    disabled?: boolean;
    values: any;
    regex?: {
      [name: string]: {
        role: any;
        name: any;
      };
    };
  }>(),
  {}
);

// console.log(props);

const emit = defineEmits(['update:values']);
//复制一份props
const getProps = computed(() => {
  return props.props;
});

const validator = (value: any, callback: any) => {
  const { componentType, name, values, required, regex } = props;
  if (componentType === 'TEXT') {
    //单行输入框
    const { validate } = getProps.value;
    if (required && !values[0]) return callback('请输入' + name);
    if (!validate) return callback();

    if (regex) {
      const roleItem = regex[validate];
      const checkVal = roleItem.role.test(values[0]);
      if (!checkVal) {
        return callback(new Error('请输入正确的' + roleItem.name));
      }
    }
  } else if (componentType === 'TEXT_AREA') {
    //多行输入框
    if (required && !values[0]) return callback(`请输入${name}`);
  } else if (componentType === 'NUMBER') {
    if (required && !values[0]) return callback(`请输入${name}`);
  } else if (componentType === 'DATE' || componentType === 'DATE_RANGE') {
    if (required && !values[0]) return callback(`请选择日期`);
  }

  callback();
};
//当value只用到第一个绑定这个参数
const oneValue = computed({
  get() {
    return props.values;
  },
  set(val) {
    emit('update:values', val);
  }
});

// 多选双向绑定
const checkGroupValue = computed({
  get() {
    return props.values;
  },
  set(val) {
    emit('update:values', val);
  }
});

// 储存数组对象的values
// const objArrValues = computed({
//   get() {
//     return props.values;
//   },
//   set(val) {
//     emit('update:values', val);
//   },
// });

// const getDepartmentList = () => {};
</script>

<style></style>
